

import delimited pnr firm year pe fe xb using "$project\manager\cvrnryear_fe_new.txt", clear
recast double pnr firm
merge m:1 firm using "$project/manager/firmyearid_cvrnr", keep(1 3) nogen
collapse fe, by (cvrnr year)
*merge manager id
merge 1:1 cvrnr year using "$project\manager\manager_all_cvrnr2", keep(1 3) keepus(pnr) nogen
drop if pnr==.
merge 1:1 cvrnr year using "$project\merger_cvrnr", keepus(nworker) keep(1 3) nogen
drop if nworker==.
drop if nworker==1

reghdfe fe , absorb(i.cvrnr i.year) res(temp)
ren fe fe0
ren temp fe

bysort pnr cvrnr: gen nyear=_N
collapse fe nworker year nyear, by (cvrnr pnr)

gsort pnr -nyear
by pnr: gen count=_n
by pnr: egen nworker_total=sum(nworker*(count<=2))
gen temp=fe if count==2
bysort pnr: egen fe2=mean(temp)

sort cvrnr year
by cvrnr: gen fe_placebo=fe[_n-1] if year-year[_n-1]>2

binscatter fe2 fe if count==1&fe>-0.2&fe<0.2, xtitle("Average residual in first firm") ytitle("Average residual in second firm")
binscatter fe2 fe_placebo if count==1&fe_p>-0.2&fe_p<0.2, xtitle("Placebo residual in first firm") ytitle("Average residual in second firm")




